package com.bins.performance.testing.log;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class LogTesting {

    private static final Integer count = 100;

    public String testDebug() {
        for (int i = 0; i < count; i++) {
            log.debug(new LogTesting.B() + "3" + "4");//就算设置了不打印debug，也会执行内容的拼接，会影响性能
        }

        return "success";
    }

    public String testDebugForEnabled() {
        for (int i = 0; i < count; i++) {
            if(log.isDebugEnabled()){
                log.debug(new byte[1024 * 1024] + "3" + "4");//就算设置了不打印debug，也会执行内容的拼接，会影响性能
            }
        }
        return "success";
    }

    public String testDebugForEnabled2() {
        for (int i = 0; i < count; i++) {
            if(log.isDebugEnabled()){
                log.debug("日志{}:{}", "3" + "4");
            }
        }
        return "success";
    }

    public class B {
        private byte[] b = new byte[1024 * 1024];
        public B() {
            System.out.println("B的初始化");
        }
    }

    public static void main(String[] args) {
        LogTesting log = new LogTesting();
        log.testDebug();
    }
}
